import React, {useContext, useEffect, useState} from 'react';
import {Alert, Dimensions, ImageBackground, ScrollView, TouchableOpacity, View} from 'react-native';
import {BottomSheet, Button, Icon, Image, Input, ListItem, Text} from 'react-native-elements';
import LocaleContext from '../libs/locale';
import WalletContext, {checkPassword} from '../libs/wallet';
import {formartMoney, sleep, timeFormat} from '../libs/helpers';
import {checkAddress} from '../libs/keyPair';
import {getBalances, getTokenBalance, getTxInfo, getTxStatus, tokenTransfer, transfer} from '../libs/nodes';
import {addTx, getTxs as getPendingTxs, getTxs2, popTx, saveTXone} from '../libs/pendingTxs';
import icon1 from '../assets/Assets/send.receiver_address.png';
import icon2 from '../assets/Assets/send.amount.png';
import icon3 from '../assets/Assets/send.contracts.png';
import logo from '../assets/logo.png';
import WaitingModal from '../components/WaitingModal';
import LoadingView from '../components/LoadingView';

import {constansts} from "./../libs/constansts";
import AsyncStorage from '@react-native-async-storage/async-storage';
import {useFocusEffect} from "@react-navigation/native";

const {width, height} = Dimensions.get("window");
console.log("屏幕=" + width + " " + height);

const Send = ({navigation, route}: any) => {
    const locale: any = useContext(LocaleContext);
    const wallet: any = useContext(WalletContext);
    const coin = route?.params?.coin;
    const tokenAddress = route?.params?.tokenAddress || "";
    const [receiver, setReceiver] = useState(route?.params?.receiver);
    const [amount, setAmount] = useState('');
    const [remarks, setRemarks] = useState('');
    const [receiverError, setReceiverError] = useState('');
    const [dataError, setDataError] = useState('');
    const [amountError, setAmountError] = useState('');
    const [balance, setBalance] = useState('');
    const [recentTxs, setRecentTxs] = useState<any>([]);
    const [recentVisible, setRecentVisible] = useState(false);
    const [sending, setSending] = useState(false);
    const [authDialogVisible, setAuthDialogVisible] = useState(false);
    const [PWDfocus, setPWDfocus] = useState(false);
    const [PwdPage, setPwdPage] = useState(0);
    const [transfering, setTransfering] = useState(false);


    const [bshow, setBshow] = useState(false);//TODO 2021-03-06 loading显示或隐藏状态
    const [prompt, setPrompt] = useState('');//TODO 2021-03-06 loading对话框文字
    const [bShowLoading, setBShowLoading] = useState(false);//TODO 2021-03-06 gif—loading显示或隐藏状态
    const [payDetailVisible, setPayDetailVisible] = useState(false);//TODO 2021-03-07支付详情对话框
    const [pwdVisible, setPwdVisible] = useState(false); //TODO 2021-03-07
    const [pwd, setPwd] = useState('');                   //TODO 2021-03-07
    const [pwdError, setPwdError] = useState('');         //TODO 2021-03-07

    var flag=false;
    const intervalSetTran = async ()=>{
        if(flag)
            return ;
        setTransfering(false);
    }
    useEffect(()=>{
        const t=setInterval(intervalSetTran,2000);
        return ()=> {
            flag=true;
            clearInterval(t);
        }
    },[])

    useEffect(() => {
        const work = async () => {
            try {
                console.log("发送页面的数据=" + coin + tokenAddress)
                if (coin == "SAT") {
                    const balances = await getBalances(wallet.address);
                    setBalance(formartMoney(balances.SAT, 4));
                } else {
                    var balances = await getTokenBalance(wallet.address, tokenAddress);
                    setBalance(formartMoney(balances.amount, 4));
                }
            } catch (e) {
                console.log('getBalances:', e);
            }
        };

        work();
        console.log("发送页面的数据=" + coin + tokenAddress)
        const t = setInterval(work, 5000);
        return () => clearInterval(t);
    }, [wallet]);

    const onShowRecent = async () => {
        try {

            var txs;
            const NTA = await AsyncStorage.getItem("@nearTranAddress");

            console.log("NTA=" + NTA);
            if (NTA != null && NTA !== "") {
                txs = JSON.parse(NTA);
                setRecentTxs(txs);
            }
        } catch (e) {
            console.log('getTxs:', e);
        }

        setRecentVisible(true);
    };

    const onRecentTxClick = async (tx: any) => {
        setRecentVisible(false);
        setReceiver(tx.address);
        setReceiverError('');
    };

    const onSend = async () => {
        setSending(true);
        setReceiverError('');
        setAmountError('');
        setPwdError("");


        let hasError = false;

        if (!receiver) {
            setReceiverError(`${locale._('enter')} ${locale._('Assets.send.receiver')}`);
            hasError = true;
        } else if (!checkAddress(receiver)) {
            setReceiverError(locale._('Assets.send.receiverInvalid'));
            hasError = true;
        } else if (receiver === wallet.address) {
            setReceiverError(locale._('Assets.send.cannotToSelf'));
            hasError = true;
        }

        if (!coin ) {
            setAmountError(locale._('Assets.send.mustSelectCoin'));
            hasError = true;
        } else {
            const n = Number.parseFloat(amount);
            const m = Number(amount);
            console.log(typeof (m));
            console.log("n=" + n + "  m=" + m);
            if (Number.isNaN(n) || n <= 0 || m.toString() == "NaN") {
                setAmountError(locale._('Assets.send.amountInvalid'));
                hasError = true;
            } else if (n > Number.parseFloat(balance)) {
                setAmountError(`${locale._('Assets.send.balanceNotEnough')}`);
                hasError = true;
            }
        }
        console.log(`SATcount:${constansts.SATcount}`)
        if(parseFloat(constansts.SATcount) < 0.002)
        {
            Alert.alert("",locale._("serviceChargeError"))
            hasError = true;
        }

        if (hasError) {
            setSending(false);
            return;
        }
        setPwdPage(1);
        // setAuthDialogVisible(true);//TODO 2021-03-07
        setPayDetailVisible(true);//TODO 2021-03-07
    };

    const onOK = async () => { //TODO 2021-03-07
        if(transfering)
        {
            Alert.alert('', "转账中");
            return;
        }
        setTransfering(true);
        if (!checkPassword(wallet, pwd)) {
            setPwdError(locale?._('Import.passwordError'));
            return;
        }
        setAuthDialogVisible(false);
        try {
            setBshow(true);//TODO 2021-03-06
            // setBShowLoading(true);//TODO 2021-03-06
            var tx: any;
            if (coin == "SAT" && tokenAddress=="") {
                let amountm = formartMoney(amount, 4);
                console.log("beforeTran amount="+amountm);
                tx = await transfer(wallet.seed, wallet.address, receiver, amountm, remarks);
            }
            else {
                var datam: any;
                let amountm = formartMoney(amount,4);
                datam = "transfer(\"" + receiver + "\"," + "\"" + amountm + "\")";
                console.log("beforeTran amount="+amountm);
                tx = await tokenTransfer(wallet.seed, wallet.address, tokenAddress, datam, remarks, receiver);
            }
            if (tx.reason!=1)
            {
                console.log("false reason="+tx.reason+"     "+ amount);
                setBshow(false);//TODO 2021-03-06
                Alert.alert(tx.reason.toString(), locale._('Assets.send.sendFail'));
                navigation.replace('Send', {coin: coin, receiver})

            }
            else
            {
                await addTx(tx);
                setBshow(false);//TODO 2021-03-06
                Alert.alert('', locale._('Assets.send.sendSuccess'), [{
                    text: locale?._('Assets.send.OK'), onPress: () => {
                        navigation.popToTop();
                        navigation.push('Txs', {kind: 'Pending'})
                    }
                }]);//TODO 交易已广播 2021-03-06
            }
        } catch (e) {
            setBshow(false);//TODO 2021-03-06
            console.log('transfer:', e);//后面添加显示详细数据
            Alert.alert('', locale._('Assets.send.sendFail'));
            navigation.replace('Send', {coin: coin, receiver})
        }
        setSending(false);
    };
    return (
        <View style={{flex: 1, margin: 20}}>
            {/* 收款地址 */}
            <View style={{flexDirection: 'row', alignItems: 'center'}}>
                <ImageBackground source={icon1} style={{width: 24, height: 24}}/>
                <Text
                    style={{fontSize: 16, fontWeight: 'bold', marginLeft: 6}}>{locale?._('Assets.send.receiver')}</Text>
            </View>
            <Input
                style={{fontSize: 15}}
                // allowFontScaling={true}
                containerStyle={{marginLeft: 12}}
                defaultValue={receiver}
                errorMessage={receiverError}
                onChangeText={(value) => setReceiver(value.trim())}
                rightIcon={<Image
                    source={icon3}
                    style={{width: 24, height: 24}}
                    onPress={onShowRecent}
                />}
            />

            {/* 转账金额  以及显示转账币种*/}
            <View style={{flexDirection: 'row', alignItems: 'center'}}>
                <ImageBackground source={icon2} style={{width: 24, height: 24}}/>
                <Text style={{fontSize: 16, fontWeight: 'bold', marginLeft: 6}}>{locale?._('Assets.send.amount')}</Text>
            </View>
            <Input
                containerStyle={{marginLeft: 12}}
                errorMessage={amountError}
                defaultValue={amount}
                placeholder={"0"}
                value={amount}
                onChangeText={(value) => {
                    // var replace = (new BigNumber((new BigNumber(value)).toFixed(4, BigNumber.ROUND_DOWN))).toString();
                    // @ts-ignore
                    var replace = value.match(/^\d*(\.?\d{0,4})/g)[0];
                    value = replace;
                    setAmount(value);
                }
                }
                rightIcon={
                    <TouchableOpacity
                        onPress={() => navigation.replace('SendSelectAsset', {receiver})}
                        style={{flexDirection: 'row', alignItems: 'center'}}
                    >
                        <Text style={{
                            marginRight: 8,
                            fontWeight: 'bold'
                        }}>{coin || locale?._('Assets.send.selectAsset')}</Text>

                        <Icon
                            name='chevron-right'
                            type='font-awesome-5'
                            size={12}
                        />
                    </TouchableOpacity>
                }
            />
            {/* 显示转账余额 */}
            {coin ?
                <View style={{marginLeft: 22, marginTop: 10, flexDirection: 'row'}}>
                    <Text
                        style={{color: '#A4A4A4FF', fontSize: 17}}>{locale?._('Assets.send.balance')}: {balance}</Text>
                    <TouchableOpacity onPress={() => setAmount(balance)}>
                        <Text style={{
                            color: '#7460E3FF',
                            fontSize: 17,
                            marginLeft: 20
                        }}>{locale?._('Assets.send.all')}</Text>
                    </TouchableOpacity>
                </View>
                : <></>}
            {/* data备注 */}
            <View style={{flexDirection: 'row', marginTop: 20, alignItems: 'center'}}>
                <Input
                    containerStyle={{marginLeft: -6}}
                    // errorMessage={}
                    defaultValue={remarks}
                    onChangeText={(value) => setRemarks(value)}
                    placeholder={locale?._('Assets.send.remarks')}
                    style={{fontSize: 15}}
                />
            </View>
            {/* 提示信息*/}
            <View style={{height:40,marginLeft:5,marginTop:2,marginBottom:13}}>
                <Text style={{color:"#734FDFFF",fontSize:15,marginLeft:5}}>{locale?._('Assets.send.Notice')} </Text>
            </View>
            {/* 空白位置 */}
            <View style={{alignItems: 'center', flex: 1}}/>
            {/* 下一步   20210312刘*/}
            <View style={{alignItems: 'center'}}>
                {receiver ?
                    <Button
                        type='outline'
                        title={locale?._('next')}
                        onPress={onSend}
                        // loading={sending}
                        // disabled={sending}
                        loadingProps={{color: '#7460E3FF'}}
                        buttonStyle={{borderColor: '#7367E3', backgroundColor: '#7367E3'}}
                        titleStyle={{color: 'white'}}
                    />
                    :
                    <Button
                        type='outline'
                        title={locale?._('next')}
                        onPress={onSend}
                        // loading={sending}
                        // disabled={sending}
                        loadingProps={{color: '#7460E3FF'}}
                        buttonStyle={{borderColor: '#C6C7CB', backgroundColor: '#C6C7CB'}}
                        titleStyle={{color: 'white'}}
                    />
                }
            </View>
            {/* 详情 和 输入密码  放弃后面的那两个   20210312刘*/}
            {
                PwdPage == 0 ?
                    <View style={{height: 0}}></View>
                    :
                    <View style={{marginTop: -height, alignItems: 'center'}}>
                        {
                            PwdPage == 0 ?
                                <View style={{height: 0}}></View>
                                :
                                (
                                    PwdPage == 1 ?
                                        <View style={{width: '110%', height: height}}>
                                            <View style={{
                                                alignItems: 'center',
                                                flex: 1,
                                                opacity: 0.5,
                                                backgroundColor: 'black'
                                            }}>
                                                <TouchableOpacity style={{height: height * 0.5, width: "100%"}}
                                                                  onPress={() => setPwdPage(0)}>
                                                </TouchableOpacity>
                                            </View>
                                            <View style={{
                                                width: "100%",
                                                backgroundColor: 'white',
                                                minHeight: 380,
                                            }}>
                                                <View style={{
                                                    flexDirection: 'row',
                                                    paddingVertical: 20,
                                                }}>
                                                    <Text style={{
                                                        fontSize: 18,
                                                        fontWeight: 'bold',
                                                        textAlign: 'center',
                                                        flex: 1
                                                    }}>{locale?._('Assets.send.payDetailTitle')}</Text>
                                                    <TouchableOpacity
                                                        style={{position: 'absolute', padding: 20}}
                                                        onPress={() => setPwdPage(0)}
                                                    >
                                                        <Icon type='font-awesome' name='close' color='#333333FF'
                                                              size={24}/>
                                                    </TouchableOpacity>
                                                </View>
                                                {/***交易金额**/}
                                                <View style={{
                                                    height: 80,
                                                    justifyContent: 'center',
                                                    alignItems: 'center'
                                                }}>
                                                    <Text
                                                        style={{fontSize: 25, fontWeight: 'bold', textAlign: 'center'}}>
                                                        -{formartMoney(amount,4)} {coin}
                                                    </Text>
                                                </View>
                                                {/*<View style={ {height:1,backgroundColor:'#8a8a8a'}}/>*/}
                                                {/***收款账户**/}
                                                <ListItem bottomDivider>
                                                    <Text style={{width: 100, fontSize: 18, textAlign: 'center'}}>
                                                        {locale?._('Assets.send.payDetailReceiver')}
                                                    </Text>
                                                    <ListItem.Content>
                                                        <ListItem.Title>{receiver}</ListItem.Title>
                                                    </ListItem.Content>
                                                </ListItem>
                                                {/***付款账户**/}
                                                <ListItem bottomDivider>
                                                    <Text style={{width: 100, fontSize: 18, textAlign: 'center'}}>
                                                        {locale?._('Assets.send.payDetailTitleSender')}
                                                    </Text>
                                                    <ListItem.Content>
                                                        <ListItem.Title>{wallet.address}</ListItem.Title>
                                                    </ListItem.Content>
                                                </ListItem>
                                                {/***‘确定’按钮**/}
                                                <TouchableOpacity style={{
                                                    width: 334,
                                                    height: 40,
                                                    justifyContent: 'center',
                                                    backgroundColor: '#088DE8',
                                                    alignItems: 'center',
                                                    alignSelf: 'center'
                                                    ,
                                                    marginTop: 20,
                                                    borderColor: '#088DE8',
                                                    borderWidth: 1,
                                                    borderRadius: 10
                                                }}
                                                                  onPress={() => {
                                                                      setPwdPage(2)
                                                                  }}>
                                                    <Text style={{
                                                        // marginTop: 160,
                                                        fontSize: 20,
                                                        textAlign: 'center',
                                                        color: 'white'
                                                    }}>{locale._('Assets.send.payDetailBtnOK')}</Text>
                                                </TouchableOpacity>
                                            </View>
                                        </View>
                                        :
                                        (
                                            PwdPage == 2 ?

                                                <View style={{width: '110%', height: height}}>
                                                    <View style={{
                                                        alignItems: 'center',
                                                        flex: 1,
                                                        backgroundColor: 'black',
                                                        opacity: 0.5
                                                    }}>
                                                        <TouchableOpacity style={{height: height * 0.5, width: "100%"}}
                                                                          onPress={() => setPwdPage(0)}>
                                                        </TouchableOpacity>
                                                    </View>
                                                    <View style={{
                                                        backgroundColor: 'white',
                                                        borderTopLeftRadius: 27,
                                                        borderTopRightRadius: 27,
                                                        minHeight: 280,
                                                    }}>
                                                        <View style={{
                                                            flexDirection: 'row',
                                                            paddingVertical: 20,
                                                        }}>
                                                            <Text style={{
                                                                fontSize: 18,
                                                                fontWeight: 'bold',
                                                                textAlign: 'center',
                                                                flex: 1
                                                            }}>{locale?._('Import.password')}</Text>
                                                            <TouchableOpacity
                                                                style={{position: 'absolute', padding: 20}}
                                                                onPress={() => setPwdPage(0)}
                                                            >
                                                                <Icon type='font-awesome' name='close' color='#333333FF'
                                                                      size={24}/>
                                                            </TouchableOpacity>
                                                        </View>
                                                        <Input
                                                            autoFocus={true}
                                                            placeholder={locale?._('Assets.send.pwHint')}
                                                            rightIcon={<Icon
                                                                name={pwdVisible ? 'eye' : 'eye-off'}
                                                                type='feather'
                                                                onPress={() => setPwdVisible(!pwdVisible)}
                                                            />}
                                                            secureTextEntry={!pwdVisible}
                                                            errorMessage={pwdError}
                                                            onChangeText={value => setPwd(value)}
                                                            // onFocus={()=>{setPWDfocus(true);}}
                                                            // onBlur={()=>{setPWDfocus(false)}}
                                                        />
                                                        <View style={{flex: 1}}></View>
                                                        <View style={{
                                                            flexDirection: 'row',
                                                            bottom: 0,
                                                            marginTop: 10,
                                                            marginBottom: 0,
                                                            alignSelf: 'center'
                                                        }}>
                                                            {
                                                                pwd
                                                                    ?
                                                                    <TouchableOpacity style={{
                                                                        width: "96%",
                                                                        height: 40,
                                                                        justifyContent: 'center',
                                                                        backgroundColor: '#088DE8',
                                                                        alignItems: 'center',
                                                                        borderColor: '#088DE8',
                                                                        borderWidth: 1,
                                                                        borderRadius: 10
                                                                    }}
                                                                        disabled={transfering}
                                                                        onPress={onOK}>
                                                                        <Text style={{
                                                                            // marginTop: 160,
                                                                            fontSize: 20,
                                                                            textAlign: 'center',
                                                                            color: 'white'
                                                                        }}>{locale._('Assets.send.payDetailBtnOK')}</Text>
                                                                    </TouchableOpacity>
                                                                    :
                                                                    <TouchableOpacity style={{
                                                                        width: "96%",
                                                                        height: 40,
                                                                        justifyContent: 'center',
                                                                        backgroundColor: '#C6C7CB',
                                                                        alignItems: 'center'
                                                                        ,
                                                                        borderColor: '#C6C7CB',
                                                                        borderWidth: 1,
                                                                        borderRadius: 10
                                                                    }} onPress={onOK}>
                                                                        <Text style={{
                                                                            // marginTop: 160,
                                                                            fontSize: 20,
                                                                            textAlign: 'center',
                                                                            color: 'white'
                                                                        }}>{locale._('Assets.send.payDetailBtnOK')}</Text>
                                                                    </TouchableOpacity>
                                                            }
                                                        </View>

                                                    </View>
                                                </View>
                                                :
                                                <View></View>
                                        )
                                )
                        }


                    </View>

            }
            {/*  // loading={sending}
      // disabled={sending}*/}
            {/***输入密码对话框***/}
            {/*<AuthDialog visible={authDialogVisible} onClose={onAuthDialogClose} />  authDialogVisible*/}

            <BottomSheet isVisible={false} modalProps={{
                statusBarTranslucent: true,
                // visible: recentVisible
            }}>

                <View style={{alignItems: 'center', flex: 1}}>
                    <TouchableOpacity style={{height: height * 0.5, width: "100%"}}
                                      onPress={() => setAuthDialogVisible(false)}>
                    </TouchableOpacity>
                </View>
                <View style={{
                    backgroundColor: 'white',
                    borderTopLeftRadius: 27,
                    borderTopRightRadius: 27,
                    minHeight: 380,
                }}>
                    <View style={{
                        flexDirection: 'row',
                        paddingVertical: 20,
                    }}>
                        <Text style={{
                            fontSize: 18,
                            fontWeight: 'bold',
                            textAlign: 'center',
                            flex: 1
                        }}>{locale?._('Import.password')}</Text>
                        <TouchableOpacity
                            style={{position: 'absolute', padding: 20}}
                            onPress={() => setAuthDialogVisible(false)}
                        >
                            <Icon type='font-awesome' name='close' color='#333333FF' size={24}/>
                        </TouchableOpacity>
                    </View>
                    <Input
                        placeholder={locale?._('Assets.send.pwHint')}
                        rightIcon={<Icon
                            name={pwdVisible ? 'eye' : 'eye-off'}
                            type='feather'
                            onPress={() => setPwdVisible(!pwdVisible)}
                        />}
                        secureTextEntry={!pwdVisible}
                        errorMessage={pwdError}
                        onChangeText={value => setPwd(value)}
                        onFocus={() => {
                            setPWDfocus(true);
                        }}
                        onBlur={() => {
                            setPWDfocus(false)
                        }}
                    />
                    {/***忘记密码**/}
                    {/*<Text style={{width:300,fontSize: 20,color: 'blue' ,textAlign: 'right',}} onPress={()=>{

               }}>
              {locale._('Assets.send.pwReset')}
          </Text>*/}

                    <View style={{flex: 1}}></View>
                    <View style={{
                        flexDirection: 'row',
                        bottom: 10,
                        marginTop: 10,
                        marginBottom: 20,
                        alignSelf: 'center'
                    }}>
                        {
                            pwd
                                ?
                                <TouchableOpacity style={{
                                    width: "96%",
                                    height: 40,
                                    justifyContent: 'center',
                                    backgroundColor: '#088DE8',
                                    alignItems: 'center'
                                    ,
                                    borderColor: '#088DE8',
                                    borderWidth: 1,
                                    borderRadius: 10
                                }} onPress={onOK}>
                                    <Text style={{
                                        // marginTop: 160,
                                        fontSize: 20,
                                        textAlign: 'center',
                                        color: 'white'
                                    }}>{locale._('Assets.send.payDetailBtnOK')}</Text>
                                </TouchableOpacity>
                                :
                                <TouchableOpacity style={{
                                    width: "96%",
                                    height: 40,
                                    justifyContent: 'center',
                                    backgroundColor: '#C6C7CB',
                                    alignItems: 'center'
                                    ,
                                    borderColor: '#C6C7CB',
                                    borderWidth: 1,
                                    borderRadius: 10
                                }} onPress={onOK}>
                                    <Text style={{
                                        // marginTop: 160,
                                        fontSize: 20,
                                        textAlign: 'center',
                                        color: 'white'
                                    }}>{locale._('Assets.send.payDetailBtnOK')}</Text>
                                </TouchableOpacity>
                        }
                    </View>
                    {
                        PWDfocus ?
                            <View style={{height: height * 0.35}}></View>
                            :
                            <View style={{height: 0}}></View>
                    }
                </View>
            </BottomSheet>
            {/***选择收款地址列表对话框 recentVisible**/}
            <BottomSheet isVisible={recentVisible} modalProps={{
                statusBarTranslucent: true,
                // visible: recentVisible
            }}>
                <View style={{
                    backgroundColor: 'white',
                    borderTopLeftRadius: 27,
                    borderTopRightRadius: 27,
                    minHeight: height / 2,
                    maxHeight: height / 1.5,
                }}>
                    <View style={{
                        flexDirection: 'row',
                        paddingVertical: 20,
                    }}>
                        <Text style={{
                            fontSize: 18,
                            fontWeight: 'bold',
                            textAlign: 'center',
                            flex: 1
                        }}>{locale?._('Assets.send.recent')}</Text>
                        <TouchableOpacity
                            style={{position: 'absolute', padding: 20}}
                            onPress={() => setRecentVisible(false)}
                        >
                            <Icon type='font-awesome' name='close' color='#333333FF' size={24}/>
                        </TouchableOpacity>
                    </View>
                    <ScrollView>
                        {
                            JSON.stringify(recentTxs) !== "[]" && recentTxs != null
                                ?
                                recentTxs.map((tx: any, index: any) => (
                                    <ListItem bottomDivider onPress={() => onRecentTxClick(tx)} key={index}>
                                        <ImageBackground source={logo} style={{width: 38, height: 38}}/>
                                        <ListItem.Content>
                                            <ListItem.Title>{tx.address}</ListItem.Title>
                                            <ListItem.Subtitle>{timeFormat(tx.timestamp)}</ListItem.Subtitle>
                                        </ListItem.Content>
                                    </ListItem>
                                ))
                                :
                                <View style={{flex: 1, justifyContent: 'center'}}>
                                    <Text style={{
                                        // marginTop: 160,
                                        fontSize: 20,
                                        textAlign: 'center',
                                        color: 'grey'
                                    }}>{locale._('noContent')}</Text>
                                </View>
                        }</ScrollView>
                </View>
            </BottomSheet>
            {/***支付详情对话框2021-03-07 payDetailVisible**/}
            <BottomSheet isVisible={false} modalProps={{
                statusBarTranslucent: true,
                // visible: recentVisible
            }}>
                <View style={{alignItems: 'center', flex: 1}}>
                    <TouchableOpacity style={{height: height * 0.5, width: "100%"}}
                                      onPress={() => setPayDetailVisible(false)}>
                    </TouchableOpacity>
                </View>
                <View style={{
                    backgroundColor: 'white',
                    borderTopLeftRadius: 27,
                    borderTopRightRadius: 27,
                    minHeight: 380,
                }}>
                    <View style={{
                        flexDirection: 'row',
                        paddingVertical: 20,
                    }}>
                        <Text style={{
                            fontSize: 18,
                            fontWeight: 'bold',
                            textAlign: 'center',
                            flex: 1
                        }}>{locale?._('Assets.send.payDetailTitle')}</Text>
                        <TouchableOpacity
                            style={{position: 'absolute', padding: 20}}
                            onPress={() => setPayDetailVisible(false)}
                        >
                            <Icon type='font-awesome' name='close' color='#333333FF' size={24}/>
                        </TouchableOpacity>
                    </View>
                    {/***交易金额**/}
                    <View style={{height: 80, justifyContent: 'center', alignItems: 'center'}}>
                        <Text style={{fontSize: 25, fontWeight: 'bold', textAlign: 'center'}}>
                            -{amount} {coin}
                        </Text>
                    </View>
                    {/*<View style={ {height:1,backgroundColor:'#8a8a8a'}}/>*/}
                    {/***收款账户**/}
                    <ListItem bottomDivider>
                        <Text style={{width: 100, fontSize: 18, textAlign: 'center'}}>
                            {locale?._('Assets.send.payDetailReceiver')}
                        </Text>
                        <ListItem.Content>
                            <ListItem.Title>{receiver}</ListItem.Title>
                        </ListItem.Content>
                    </ListItem>
                    {/***付款账户**/}
                    <ListItem bottomDivider>
                        <Text style={{width: 100, fontSize: 18, textAlign: 'center'}}>
                            {locale?._('Assets.send.payDetailTitleSender')}
                        </Text>
                        <ListItem.Content>
                            <ListItem.Title>{wallet.address}</ListItem.Title>
                        </ListItem.Content>
                    </ListItem>
                    {/***‘确定’按钮**/}
                    <TouchableOpacity style={{
                        width: 334,
                        height: 40,
                        justifyContent: 'center',
                        backgroundColor: '#088DE8',
                        alignItems: 'center',
                        alignSelf: 'center'
                        ,
                        marginTop: 20,
                        borderColor: '#088DE8',
                        borderWidth: 1,
                        borderRadius: 10
                    }}
                                      onPress={() => {
                                          setPayDetailVisible(false);
                                          setAuthDialogVisible(true)
                                      }}>
                        <Text style={{
                            // marginTop: 160,
                            fontSize: 20,
                            textAlign: 'center',
                            color: 'white'
                        }}>{locale._('Assets.send.payDetailBtnOK')}</Text>
                    </TouchableOpacity>
                </View>
            </BottomSheet>
            {/* @ts-ignore*/}
            <WaitingModal show={bshow} prompt={prompt}/>{/***2021-03-06*/}
            {/* @ts-ignore*/}
            <LoadingView showLoading={bShowLoading}/>{/***2021-03-06*/}
        </View>
    );
};
export default Send;
